import { request } from '../request';

/** 获取媒体目录配置 */
export function fetchMediaConfig() {
    return request<{
        filmPath: Api.Config.ConfigItem;
        seriesPath: Api.Config.ConfigItem;
        excludePath: Api.Config.ConfigItem;
    }>({
        url: '/Caches/MediaDirectoryConfiguration',
        method: 'get'
    });
}

/** 修改媒体目录配置 */
export function saveMediaConfig(data: Api.Config.MediaConfig) {
    return request<number>({
        url: `/Caches/MediaDirectoryConfiguration`,
        method: 'put',
        data: {
            filmPath: {
                id: data.filmPath?.id || null,
                name: data.filmPath?.name || null,
                key: data.filmPath?.key || null,
                value: data.moviePaths,
                groupName: data.filmPath?.groupName || null
            },
            seriesPath: {
                id: data.seriesPath?.id || null,
                name: data.seriesPath?.name || null,
                key: data.seriesPath?.key || null,
                value: data.tvPaths,
                groupName: data.seriesPath?.groupName || null
            },
            excludePath: {
                id: data.excludePath?.id || null,
                name: data.excludePath?.name || null,
                key: data.excludePath?.key || null,
                value: data.excludePaths,
                groupName: data.excludePath?.groupName || null
            }
        }
    });
}

/** 获取百度翻译API配置 */
export function fetchTranslateConfig() {
    return request<Api.Config.TranslateConfig>({
        url: '/Caches/BaiduTranslationAPIConfiguration',
        method: 'get'
    });
}

/** 修改百度翻译API配置 */
export function saveTranslateConfig(data: Api.Config.TranslateConfig) {
    return request<number>({
        url: `/Caches/BaiduTranslationAPIConfiguration`,
        method: 'put',
        data: {
            id: data.id,
            appId: data.appId,
            secretKey: data.secretKey
        }
    });
}

/** 获取AI配置 */
export function fetchAIConfig() {
    return request<Api.Config.AIConfig>({
        url: '/Caches/AIConfiguration',
        method: 'get'
    });
}

/** 修改AI配置 */
export function saveAIConfig(data: Api.Config.AIConfig) {
    return request<number>({
        url: `/Caches/AIConfiguration`,
        method: 'put',
        data: {
            // id: data.id,
            enabled: data.enabled,
            apiKey: data.apiKey,
            baseUrl: data.baseUrl,
            model: data.model
        }
    });
}

/** 获取提示词 */
export function fetchPromptWord() {
    return request<string>({
        url: '/Caches/ModifyPromptWordQuery',
        method: 'get'
    });
}

/** 修改提示词 */
export function savePromptWord(data: string) {
    return request<number>({
        url: '/Caches/ModifyPromptWordQuery?promptWord=' + data,
        method: 'put',
    });
}
/** 获取排序 */
export function fetchTranslationOrdering() {
    return request<Api.Translation.PriorityItem[]>({
        url: '/Caches/ConfigOrdering',
        method: 'get',
    });
}
/** 修改排序 */
export function saveTranslationOrdering(data: { id: string; sort: number }) {
    return request<number>({
        url: `/Caches/ConfigOrdering/${data.id}`,
        method: 'put',
        params: { sort: data.sort }
    });
}
